package com.ecable.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ecable.daoImpl.ProfileDAO;
import com.ecable.bean.ProfileTO;
import com.sun.org.apache.commons.beanutils.BeanUtils;
public class RegisterAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String target = "Registerform.jsp?status=Registration Failed";
		ProfileTO p = new ProfileTO();
		Map map = request.getParameterMap();
		try {
			BeanUtils.populate(p, map);

		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InvocationTargetException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			boolean flag = new ProfileDAO().registration(p);
			if (flag)
				target = "LoginForm.jsp?status=Registration Success";
			else
				target = "Registerform.jsp?status=Registration Failed";
		} catch (Exception e) {
			e.printStackTrace();
		}
		RequestDispatcher rd = request.getRequestDispatcher(target);
		rd.forward(request, response);
	}

}
